package cn.com.ejiakanghu.dto;

import cn.com.ejiakanghu.config.LocationContext;
import cn.com.ejiakanghu.goods.dto.GoodsPriceInfo;
import cn.com.ejiakanghu.goods.dto.GoodsTag;
import org.apache.commons.lang.StringUtils;
import org.linlinjava.litemall.core.util.JacksonUtil;
import org.linlinjava.litemall.db.domain.LitemallGoods;
import org.linlinjava.litemall.db.vo.app.StoreGoodsVo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author houzb
 * @Description
 * @create 2021-04-14 21:21
 */
public class CollectGoodsData {
    /**
     * 商品id
     */
    private int id;
    /**
     * 商品名称
     */
    private String name;
    /**
     * 商品主图URL，图片宽高尺寸比例:320*320
     */
    private String mainImage;
    /**
     * 商品类型
     */
    private String type;

    /**
     * 商品标签列表
     */
    private List<GoodsTag> tags;

    /**
     * 商品价格信息
     */
    private GoodsPriceInfo priceInfo;
    /**
     * 商品是否已下架
     */
    private int isOffline;
    /**
     * 商品是否已失效,商品可以看，但不能购买
     */
    private int isInvalid;
    /**
     * 商品是否不支持购买，商品可以看但不能买
     */
    private int isDisabled;

    /**
     * 购买或租赁当前商品可获得的抵扣金数量
     */
    private double deductNum;

    /**
     * 省份
     */
    private String province;

    /**
     * 城市
     */
    private String city;

    private String shareTitle;

    private Integer isHospital;

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public double getDeductNum() {
        return deductNum;
    }

    public void setDeductNum(double deductNum) {
        this.deductNum = deductNum;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMainImage() {
        return mainImage;
    }

    public void setMainImage(String mainImage) {
        this.mainImage = mainImage;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public List<GoodsTag> getTags() {
        return tags;
    }

    public void setTags(List<GoodsTag> tags) {
        this.tags = tags;
    }

    public GoodsPriceInfo getPriceInfo() {
        return priceInfo;
    }

    public void setPriceInfo(GoodsPriceInfo priceInfo) {
        this.priceInfo = priceInfo;
    }

    public int getIsOffline() {
        return isOffline;
    }

    public void setIsOffline(int isOffline) {
        this.isOffline = isOffline;
    }

    public int getIsInvalid() {
        return isInvalid;
    }

    public void setIsInvalid(int isInvalid) {
        this.isInvalid = isInvalid;
    }

    public int getIsDisabled() {
        return isDisabled;
    }

    public void setIsDisabled(int isDisabled) {
        this.isDisabled = isDisabled;
    }

    public String getShareTitle() {
        return shareTitle;
    }

    public void setShareTitle(String shareTitle) {
        this.shareTitle = shareTitle;
    }

    public Integer getIsHospital() {
        return isHospital;
    }

    public void setIsHospital(Integer isHospital) {
        this.isHospital = isHospital;
    }

    public void init(StoreGoodsVo goods) {
        this.id = goods.getStoreGoodsId();
        this.name = goods.getName();
        this.mainImage = goods.getPicUrl();
        String gTags = goods.getTags();
        this.tags = StringUtils.isNotBlank(gTags) ? JacksonUtil.gson.fromJson(gTags, List.class) : new ArrayList<>();
        this.priceInfo = new GoodsPriceInfo(goods);
        this.isOffline = goods.getIsOnSale() ? 0 : 1;
        this.province = goods.getProvince();
        this.city = goods.getCity();

//        Location location = LocationContext.get();
//        if (location.getProvince().equals(goods.getProvince()) && location.getCity().equals(goods.getCity())) {
//            this.isDisabled = 0;
//            this.isInvalid = 0;
//        } else {
//            this.isDisabled = 1;
//            this.isInvalid = 1;
//        }
        this.type = goods.getGoodsType();
        this.shareTitle = goods.getShareUrl();
        this.isHospital = goods.getIsHospital();
    }

}
